define(['egis'], function (egis) {
    Window.deserializer = Window.deserializer || new egis.core.Deserializer();
    Window.container = Window.container || {};
    dsBridge.register('create_RestWRDSService', function (sourceId, url, http, authType, clientId, clientSecret,tokenUrl) {
        var restHttp = Window.container[http];
        var restGeoService = new egis.ews.RestWRDSService({
            url: url,
            http: restHttp,
            deserializer: Window.deserializer,
            authType: authType,
            clientId: clientId,
            clientSecret: clientSecret,
            tokenUrl:tokenUrl
        });
        Window.container[sourceId] = restGeoService;
    })

    dsBridge.registerAsyn('RestWRDSService_rescueAnalysis', function (sourceId, layer,destination, requiredResList, requiredRoute, responseCallback) {
       var restWRDSService = Window.container[sourceId];
              destination = Window.deserializer.createJsInstance(JSON.parse(destination));
              requiredResList = Window.deserializer.createJsInstance(JSON.parse(requiredResList));
              requiredResList.forEach(function (entity) {
                          entity['$type'] = 'Resource,http://www.Gs.com';
                      })
              restWRDSService.rescueAnalysis(layer,destination, requiredResList, requiredRoute).then(function (value) {
                  responseCallback(JSON.stringify(value));
              })
    })

    dsBridge.registerAsyn('RestWRDSService_materialAnalysis', function (sourceId, layer,destination, requiredResList, requiredRoute, responseCallback) {
        var restWRDSService = Window.container[sourceId];
        destination = Window.deserializer.createJsInstance(JSON.parse(destination));
        requiredResList = Window.deserializer.createJsInstance(JSON.parse(requiredResList));
        requiredResList.forEach(function (entity) {
                                  entity['$type'] = 'Resource,http://www.Gs.com';
                              })
        restWRDSService.materialAnalysis(layer,destination, requiredResList, requiredRoute).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWRDSService_equipmentAnalysis', function (sourceId, layer, destination, requiredResList, requiredRoute, responseCallback) {
        var restWRDSService = Window.container[sourceId];
        destination = Window.deserializer.createJsInstance(JSON.parse(destination));
        requiredResList = Window.deserializer.createJsInstance(JSON.parse(requiredResList));
        requiredResList.forEach(function (entity) {
                                  entity['$type'] = 'Resource,http://www.Gs.com';
                              })
        restWRDSService.equipmentAnalysis(layer, destination, requiredResList, requiredRoute).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
    dsBridge.registerAsyn('RestWRDSService_route', function (sourceId, layer, origin, destination, responseCallback) {
        var restWRDSService = Window.container[sourceId];
        origin = Window.deserializer.createJsInstance(JSON.parse(origin));
        destination = Window.deserializer.createJsInstance(JSON.parse(destination));
        restWRDSService.route(layer, origin, destination).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
})